import React, {Component} from 'react';
import {withRouter} from 'react-router'
import './style.css';

import JudgeProjectItem from '../../components/JudgeProjectItem';


class Home extends Component {


    _continueJudge = (index) => {

        const {history} = this.props;

        history.push({
            pathname: '/judge',
            state: {
                projectId: index,
                canMark: true
            }
        });


    };

    _goDetail = (index) => {
        const {history} = this.props;
        history.replace({
            pathname: '/judge', state: {
                projectId: index,
                canMark: false
            }
        });
    };

    render() {
        const {JudgeProjects} = this.props;
        let no = 0;
        return <div className="indexContainer">
            <table className="judgeTable">
                <thead>
                <th>序号</th>
                <th>考核名称</th>
                <th>项目名称</th>
                <th>单位名称</th>
                <th>创建时间</th>
                <th>操作</th>
                </thead>
                <tbody>

                {JudgeProjects ? Object
                    .keys(JudgeProjects).map(key => {
                            no++;
                            return <JudgeProjectItem no={no} deleteJudgeProject={this.props.deleteJudgeProject} index={key}
                                                     continueJudge={this._continueJudge}
                                                     goDetail={this._goDetail}
                                                     key={key} detail={JudgeProjects[key]}/>
                        }
                    ) : <tr>
                    <td colSpan={6}>还没有添加考核</td>
                </tr>}
                </tbody>
            </table>

        </div>

    }
}

export default withRouter(Home);